/**
 * Created by RickyTT on 14-1-28.
 */

var Post = require('../model/post.js');

exports.post = function(req,res){
    Post.insert(req.session.user.id,req.session.user.name,req.body.post,function(err,result){
        if(err || !result){
            req.flash('error','发表失败');
            return res.redirect('/');
        }else{
            req.flash('success','发表成功');
            res.redirect('/');
        };
    });
};


exports.deletePost = function(req,res){
    Post.deleteById(req.params.postId,function(err,result){
        if(err || !result){
            req.flash('error','删除失败');
            return res.redirect('/');
        }else{
            req.flash('success','删除成功');
            res.redirect('/');
        };
    });
};